package com.eedi.framework.sensitiveword.dal.mapper;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.sensitiveword.controller.sys.vo.SysSensitiveWordPageReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.eedi.framework.sensitiveword.dal.dataobject.SysSensitiveWordDO;
import java.time.LocalDateTime;

/**
 * 敏感词 Mapper
 *
 * @author 永不言败
 */
@Mapper
public interface SysSensitiveWordMapper extends BaseMapperX<SysSensitiveWordDO> {

    default PageResult<SysSensitiveWordDO> selectPage(SysSensitiveWordPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysSensitiveWordDO>()
                .likeIfPresent(SysSensitiveWordDO::getSysSensitiveName, reqVO.getSysSensitiveName())
                .likeIfPresent(SysSensitiveWordDO::getSysSensitiveTags, reqVO.getSysSensitiveTag())
                .eqIfPresent(SysSensitiveWordDO::getSysSensitiveStatus, reqVO.getSysSensitiveStatus())
                .betweenIfPresent(SysSensitiveWordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SysSensitiveWordDO::getId));
    }

    default SysSensitiveWordDO selectByName(String name) {
        return selectOne(SysSensitiveWordDO::getSysSensitiveName, name);
    }

    @Select("SELECT COUNT(*) FROM system_sensitive_word WHERE update_time > #{maxUpdateTime}")
    Long selectCountByUpdateTimeGt(LocalDateTime maxTime);

}
